package com.rainy.cloud.gateway.limiter;

import org.springframework.cloud.gateway.filter.ratelimit.RedisRateLimiter;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.data.redis.core.script.RedisScript;
import org.springframework.validation.Validator;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * 自定义处理Limiter是否通过
 * @author user
 */
public class RainyRateLimiter extends RedisRateLimiter {

    public RainyRateLimiter(ReactiveRedisTemplate<String, String> redisTemplate, RedisScript<List<Long>> script, Validator validator) {
        super(redisTemplate, script, validator);
    }

    @Override
    public Mono<Response> isAllowed(String routeId, String id) {
        Mono<Response> mono = super.isAllowed(routeId, id);
//        Config defaultConfig = new Config().setReplenishRate(1).setBurstCapacity(1);
//        Config routeConfig = getConfig().getOrDefault(routeId, defaultConfig);
//        //判断条件是否通过
//        Boolean flag = Boolean.TRUE;
//        if (flag) {
//            return Mono.just(new Response(false, getHeaders(routeConfig, -1L)));
//        }
        return mono;
    }
}
